<?php
include '../Model/ModelConexion.php';

	$ob=new Conexion();
	$hora_I= 8;
	$hora_II= 11;
  $h=9;
      $hora_F=11;
      $resta_hora=$hora_F-1;
      $m_ca_hora_F=$resta_hora.':55';

	    echo $m_ca_hora_F;
	 //este if es para verificar el valor y si esta en ese rango se le agrega un 0(cero) antes, ya que para la consulta es necesario el 0(cero)
	if ($hora_I < 7 || $hora_I <= 9  ) 
	{

		echo "entre al 1er if\n";	echo "<br>";
		$hora__='00:00:00'.$hora_I; 
		$hora__II='00:00:0'.$hora_II;

    echo '<<<<<<<<<<<<<<<<<00:0'.$hora_I.':20>>>>>>>>>>>>';
	}else
	{
		echo "no entre al 1er if\n";echo "<br>";
		$hora__='00:00:'.$hora_I;
		$hora__II='00:00:'.$hora_II;
	}

	if ($hora_II < 7 || $hora_II <= 9 ) 
	{
		echo "entre al 2do if\n";	echo "<br>";
		$hora__='00:00:0'.$hora_I; 
		$hora__II='00:00:0'.$hora_II;
	}
	else
	{
		echo "no entre al 2do if\n";echo "<br>";
		$hora__='00:00:'.$hora_I;
		$hora__II='00:00:'.$hora_II;
	}
 	
   	$consulta = $ob->Consulta("
       SELECT cadetalles.aula as a,cadetalles.horaI as i,cadetalles.horaF as f
       FROM cadetalles
       WHERE TIME('$hora__') BETWEEN cadetalles.horaI AND cadetalles.horaF
       AND TIME('00:00:07')<cadetalles.horaI
       AND cadetalles.aula='3'
       AND cadetalles.dia='Martes'
       AND cadetalles.codigoHorario='2015I'
       AND cadetalles.horaF<TIME('00:00:22');
        ");

    if($ob->get_m_us_filas_afectadas()>=1)
    {
      //true=esta ocupada
    	echo "<br>";
		echo "$hora__";
    	echo "<br>";
    	echo "$hora_I";
     	echo "<br>";
    	echo "true I";
    	echo "<br>";

    }else
    {
      
    	echo "$hora__";
    	echo "<br>";
    	echo "$hora_I";
     	echo "<br>";
    	echo "false I";
    	echo "<br>";
    }

     	$consulta_II = $ob->Consulta("
       SELECT cadetalles.aula as a,cadetalles.horaI as i,cadetalles.horaF as f
       FROM cadetalles
       WHERE TIME('$hora__II') BETWEEN cadetalles.horaI AND cadetalles.horaF
       AND TIME('00:00:07')<cadetalles.horaI
       AND cadetalles.aula='3'
       AND cadetalles.dia='Lunes'
       AND cadetalles.codigoHorario='2014I'
       AND cadetalles.horaF<TIME('00:00:22');
        ");

    if($ob->get_m_us_filas_afectadas()>=1)
    {
			echo "<br>";
    		echo "$hora__II";
    		echo "<br>";
		    echo "$hora_II";
     		echo "<br>";
    		echo "true II";
    		echo "<br>";
    }else
    {
    		echo "<br>";
    		echo "$hora__II";
    		echo "<br>";
	    	echo "$hora_II";
     		echo "<br>";
    		echo "false II";
    		echo "<br>";
    }

        $consulta_Prof_Inverso = $ob->Consulta("
       SELECT cadetalles.aula,cadetalles.horaI,cadetalles.horaF
       FROM cadetalles 
       WHERE cadetalles.horaI BETWEEN TIME('$hora__') AND TIME('$hora__II')
       AND TIME('00:00:07')<cadetalles.horaI
       AND cadetalles.aula='3'
       AND cadetalles.dia='Lunes' 
       AND cadetalles.codigoHorario='2014I'
       AND cadetalles.horaF<TIME('22:00:00');   
        ");
         if($ob->get_m_us_filas_afectadas()>=1)
        {
           	echo "<br>";
		   	echo "$hora__II";
		    echo "<br>";
		    echo "$hora_II";
		    echo "<br>";
		   	echo "true Inverso";
		   	echo "<br>";
        }
        else
        {
          //false=esta desocupada
            echo "<br>";
			echo "$hora__II";
			echo "<br>";
			echo "$hora_II";
			echo "<br>";
			echo "false Inverso";
			echo "<br>";
        }

        $consulta_Prof_InversoII = $ob->Consulta("
       SELECT cadetalles.aula,cadetalles.horaI,cadetalles.horaF
       FROM cadetalles 
       WHERE cadetalles.horaF BETWEEN TIME('$hora__') AND TIME('$hora__II')
       AND TIME('00:00:07')<cadetalles.horaI
       AND cadetalles.aula='3'
       AND cadetalles.dia='Lunes' 
       AND cadetalles.codigoHorario='2014I'
       AND cadetalles.horaF<TIME('22:00:00');   
        ");
         if($ob->get_m_us_filas_afectadas()>=1)
        {
           	echo "<br>";
		   	echo "$hora__";
		    echo "<br>";
		    echo "$hora__II";
		    echo "<br>";
		   	echo "true InversoII";
		   	echo "<br>";
        }
        else
        {
          //false=esta desocupada
            echo "<br>";
			echo "$hora__";
		    echo "<br>";
		    echo "$hora__II";
			echo "<br>";
			echo "false InversoII";
			echo "<br>";
        }

         $ob->Consulta("
        INSERT INTO cadetalles
            (cedula,
             nrc,
             codigoCurso,
             codigoHorario,
             aula,
             horaI,
             horaF,
             grupo,
             dia)
        VALUES('5039702',
              '2233',
              'PRE911',
              '2014I',
              '1',
              '00:00:08',
              '00:00:11',
              '11',
              'Lunes');
        ");
      if($ob->get_m_us_filas_afectadas()>=1)
      {
        echo "<br>";
        echo "si inserte en bd";
      }
      else
      {
        echo "<br>";
        echo "no inserte en bd";
          echo "<br>";
      }
        $entrada='2014II';
         $anno_true=substr($entrada, 0, 4);

       $consulta_verificar_dl = $ob->Consulta("
        SELECT DISTINCT pacademico_panno.cedula 
        FROM pacademico_panno,papersonal
        WHERE papersonal.cedula=pacademico_panno.cedula
        AND pacademico_panno.anno='$anno_true'
        AND pacademico_panno.cedula='503970269';
        ");
         if($ob->get_m_us_filas_afectadas()>=1)
        {
          //true=esta ocupada
           echo "<br>";
           echo"año true: $anno_true";
           echo "<br>";
        echo "prof si tiene datos";
          echo "<br>";
        }
        else
        {
            echo "<br>";
            echo"año true: $anno_true";
            echo "<br>";
        echo "prof no tiene datos";
          echo "<br>";
        }
/*   while($fila=$ob->Arreglo($consulta))
     {
     	echo "-".$fila['a']."-";
     	echo "<br>";
     	echo "-".$fila['i']."-";
     	echo "<br>";
     	echo "-".$fila['f']."-";
     }	*/			



     echo "<br>//pruebas para consulta_verificar_dl";

      $entrada2='2014II';
         $anno_true2=substr($entrada2, 0, 4);
     $consulta_verificar_dl = $ob->Consulta("
      SELECT DISTINCT pacademico_panno.cedula 
        FROM pacademico_panno,papersonal
        WHERE papersonal.cedula=pacademico_panno.cedula
        AND pacademico_panno.anno='$anno_true2'
        AND pacademico_panno.cedula='503970269';
        ");
         if($ob->get_m_us_filas_afectadas()>=1)
        {
          //true=esta ocupada
          echo "<br>True ";
        }
        else
        {
          //false=esta desocupada
          
          echo "<br>false";
        }
?>